//package com.cenntro.oss.common.db2;
//
//import javax.sql.DataSource;
//
//import org.apache.ibatis.session.SqlSessionFactory;
//import org.mybatis.spring.SqlSessionFactoryBean;
//import org.mybatis.spring.SqlSessionTemplate;
//import org.mybatis.spring.annotation.MapperScan;
//import org.springframework.beans.factory.annotation.Qualifier;
//import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
//import org.springframework.boot.context.properties.ConfigurationProperties;
//import org.springframework.boot.jdbc.DataSourceBuilder;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.context.annotation.Primary;
//import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
//import org.springframework.jdbc.datasource.DataSourceTransactionManager;
//
//import com.alibaba.druid.pool.DruidDataSource;
//@Configuration
//@MapperScan(basePackages = "com.cenntro.**.mapper", sqlSessionTemplateRef  = "masterSqlSessionTemplate")
//public class MasterDataSourceConfig {
//
//    @Bean(name = "masterDataSource")
////    @ConfigurationProperties(prefix = "spring.datasource.master")
//    public DataSource getDataSource() {
//    	DataSource db = masterDataSourceProperties().initializeDataSourceBuilder().build();
//    	DruidDataSource ds = (DruidDataSource)db;
//    	ds.setInitialSize(5);
//    	ds.setMaxActive(20);
//    	return db;
//    }
//
//    @Bean
//    @Primary
//    //获取Environment属性，Environment从.properties文件获取配置信息
//    @ConfigurationProperties("spring.datasource.master")
//    public DataSourceProperties masterDataSourceProperties() {
//    	return new DataSourceProperties();
//    }
//    @Bean(name = "masterSqlSessionFactory")
//    //@Primary
//    public SqlSessionFactory getSqlSessionFactory(@Qualifier("masterDataSource") DataSource dataSource) throws Exception {
//        SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
//        bean.setDataSource(dataSource);
//        bean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath*:mybatis/**/*.xml"));
//        return bean.getObject();
//    }
//
//    @Bean(name = "masterTransactionManager")
//    //@Primary
//    public DataSourceTransactionManager getTransactionManager(@Qualifier("masterDataSource") DataSource dataSource) {
//        return new DataSourceTransactionManager(dataSource);
//    }
//
//    @Bean(name = "masterSqlSessionTemplate")
//    //@Primary
//    public SqlSessionTemplate getSqlSessionTemplate(@Qualifier("masterSqlSessionFactory") SqlSessionFactory sqlSessionFactory) throws Exception {
//        return new SqlSessionTemplate(sqlSessionFactory);
//    }
//
//}